<template>
  <a-modal
    title="新增"
    :visible="visible"
    ok-text='确定'
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-form-model ref='form' :model='model' :rules='validatorRules'>
      <a-form-model-item label='标准内容' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='normName'>
        <a-textarea placeholder="请输入标准内容" v-model='model.normName' :auto-size="{ minRows: 5, maxRows: 15 }"></a-textarea>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
  import {httpAction} from '@/api/manage'

  export default {
    name: 'score',
    components: {},
    data() {
      return {
        model: {normName: ''},
        visible: false,
        validatorRules: {
          normName: [{required: true, message: '填写计分标准!'}],
        },
        labelCol: {
          xs: {span: 24},
          sm: {span: 5}
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16}
        },
        url: {
          createNorm: '/performcheck/checkScoreNorm/createNorm',
          updateNorm: '/performcheck/checkScoreNorm/updateNorm'
        },
      }
    },
    created() {
    },
    methods: {
      edit(record) {
        this.model = Object.assign({}, record)
        this.visible = true
      },
      add(id) {
        this.model = {typeId: id}
        this.visible = true
      },
      handleSubmit() {
        this.$refs.form.validate((valid) => {
          if (valid) {
            let url, type
            if (!this.model.id) {
              url = this.url.createNorm
              type = 'post'
            } else {
              url = this.url.updateNorm
              type = 'put'
            }
            httpAction(url, this.model, type).then((res) => {
              if (res.success) {
                this.$message.success(res.message)
                this.visible = false
                this.$emit('ok')
              } else {
                this.$message.error(res.message);
              }
            })
          }
        })
      },
      handleCancel(e) {
        this.visible = false;
      },
    }
  }
</script>

<style scoped>

</style>
